USE [master]
GO

/****** Object:  Database [MultiFactorEx]    Script Date: 28/10/2015 11:58:27 ******/
CREATE DATABASE [MultiFactorEx]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'MultiFactorEx', FILENAME = N'D:\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\MultiFactorEx.mdf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'MultiFactorEx_log', FILENAME = N'D:\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DataLogs\MultiFactorEx_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO

ALTER DATABASE [MultiFactorEx] SET COMPATIBILITY_LEVEL = 110
GO

IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [MultiFactorEx].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO

ALTER DATABASE [MultiFactorEx] SET ANSI_NULL_DEFAULT OFF 
GO

ALTER DATABASE [MultiFactorEx] SET ANSI_NULLS OFF 
GO

ALTER DATABASE [MultiFactorEx] SET ANSI_PADDING OFF 
GO

ALTER DATABASE [MultiFactorEx] SET ANSI_WARNINGS OFF 
GO

ALTER DATABASE [MultiFactorEx] SET ARITHABORT OFF 
GO

ALTER DATABASE [MultiFactorEx] SET AUTO_CLOSE OFF 
GO

ALTER DATABASE [MultiFactorEx] SET AUTO_CREATE_STATISTICS ON 
GO

ALTER DATABASE [MultiFactorEx] SET AUTO_SHRINK ON 
GO

ALTER DATABASE [MultiFactorEx] SET AUTO_UPDATE_STATISTICS ON 
GO

ALTER DATABASE [MultiFactorEx] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO

ALTER DATABASE [MultiFactorEx] SET CURSOR_DEFAULT  GLOBAL 
GO

ALTER DATABASE [MultiFactorEx] SET CONCAT_NULL_YIELDS_NULL OFF 
GO

ALTER DATABASE [MultiFactorEx] SET NUMERIC_ROUNDABORT OFF 
GO

ALTER DATABASE [MultiFactorEx] SET QUOTED_IDENTIFIER OFF 
GO

ALTER DATABASE [MultiFactorEx] SET RECURSIVE_TRIGGERS OFF 
GO

ALTER DATABASE [MultiFactorEx] SET  DISABLE_BROKER 
GO

ALTER DATABASE [MultiFactorEx] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO

ALTER DATABASE [MultiFactorEx] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO

ALTER DATABASE [MultiFactorEx] SET TRUSTWORTHY OFF 
GO

ALTER DATABASE [MultiFactorEx] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO

ALTER DATABASE [MultiFactorEx] SET PARAMETERIZATION SIMPLE 
GO

ALTER DATABASE [MultiFactorEx] SET READ_COMMITTED_SNAPSHOT OFF 
GO

ALTER DATABASE [MultiFactorEx] SET HONOR_BROKER_PRIORITY OFF 
GO

ALTER DATABASE [MultiFactorEx] SET RECOVERY SIMPLE 
GO

ALTER DATABASE [MultiFactorEx] SET  MULTI_USER 
GO

ALTER DATABASE [MultiFactorEx] SET PAGE_VERIFY CHECKSUM  
GO

ALTER DATABASE [MultiFactorEx] SET DB_CHAINING OFF 
GO

ALTER DATABASE [MultiFactorEx] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO

ALTER DATABASE [MultiFactorEx] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO

ALTER DATABASE [MultiFactorEx] SET  READ_WRITE 
GO


USE [MultiFactorEx]
GO

/****** Object:  Table [dbo].[REGISTRATIONS]    Script Date: 28/10/2015 11:59:16 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[REGISTRATIONS](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[UPN] [varchar](50) NOT NULL,
	[SECRETKEY] [uniqueidentifier] NULL CONSTRAINT [DF_REGISTRATIONS_SECRETKEY]  DEFAULT (newid()),
	[MAILADDRESS] [varchar](50) NULL,
	[PHONENUMBER] [varchar](50) NULL,
	[ENABLED] [bit] NOT NULL CONSTRAINT [DF_REGISTRATIONS_ENABLED]  DEFAULT ((1)),
	[CREATIONDATE] [datetime] NULL CONSTRAINT [DF_REGISTRATIONS_CREATIONDATE]  DEFAULT (getdate()),
	[METHOD] [int] NOT NULL CONSTRAINT [DF_REGISTRATIONS_PREFEREDMETHOD]  DEFAULT ((0)),
 CONSTRAINT [PK_REGISTRATIONS] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_REGISTRATIONS_UPN] UNIQUE NONCLUSTERED 
(
	[UPN] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [MultiFactorEx]
GO

/****** Object:  Table [dbo].[NOTIFICATIONS]    Script Date: 28/10/2015 11:59:34 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[NOTIFICATIONS](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[REGISTRATIONID] [bigint] NOT NULL,
	[OTP] [int] NOT NULL,
	[CREATIONDATE] [datetime] NOT NULL CONSTRAINT [DF_NOTIFICATIONS_CREATIONDATE]  DEFAULT (getdate()),
	[VALIDITYDATE] [datetime] NOT NULL,
	[CHECKDATE] [datetime] NULL,
 CONSTRAINT [PK_NOTIFICATIONS] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO


USE [MultiFactorEx]
GO

/****** Object:  View [dbo].[LAST_NOTIFICATIONS]    Script Date: 28/10/2015 12:00:20 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[LAST_NOTIFICATIONS]
AS
SELECT        R.ID AS REGISTRATIONID, N.ID AS NOTIFICATIONID, R.UPN, N.OTP, N.CREATIONDATE, N.VALIDITYDATE, N.CHECKDATE, R.SECRETKEY, R.PHONENUMBER, R.MAILADDRESS
FROM            dbo.REGISTRATIONS AS R INNER JOIN
                         dbo.NOTIFICATIONS AS N ON R.ID = N.REGISTRATIONID
WHERE        (R.ENABLED <> 0)

GO





